﻿using CsharpHttpHelper;
using CsharpHttpHelper.Enum;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Policy;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CsharpHttpHelper_Demo
{
    public partial class test : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //===================================header======================================

            //创建Httphelper对象
            HttpHelper http = new HttpHelper();
            //创建Httphelper参数对象
            HttpItem item = new HttpItem()
            {
                URL = "http://www.faxin.cn/login.aspx",//URL     必需项    
                Method = "get",//URL     可选项 默认为Get   
                ContentType = "text/html",//返回类型    可选项有默认值   
            };

            //请求的返回值对象
            HttpResult result = http.GetHtml(item);
            //获取请请求的Html
            string html = result.Html;
            //获取请求的Cookie
            string cookie1 = HttpHelper.GetSmallCookie(result.Cookie);

            //Header
            //WebHeaderCollection header = result.Header;
            WebHeaderCollection header = new WebHeaderCollection();
            header["Accept-Encoding"] = "gzip, deflate";
            header["Accept-Language"] = "zh-CN,zh;q=0.9";
            header["Cache-Control"] = "max-age=0"; 
            header["Origin"] = "http://www.faxin.cn";
            header["Upgrade-Insecure-Requests"] = "1";

            item = new HttpItem()
            {
                URL = "http://www.faxin.cn/login.aspx",//URL     必需项    
                Method = "POST",//URL     可选项 默认为Get   
                PostDataType = PostDataType.String,//默认为字符串，同时支持Byte和文件方法
                PostEncoding = System.Text.Encoding.UTF8,//默认为Default，
                Postdata = "__VIEWSTATE=%2FwEPDwUKLTQ3MzE1NzE2MWQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgIFCmlzUmVtZW1iZXIFC2lzQXV0b0xvZ2luBX5spPlbkbdaOOfsiLY2g0mJe7M%3D&__VIEWSTATEGENERATOR=C2EE9ABB&WebUCHead_Special1%24hiddIsLogin=0&WebUCSearchNoAdvSearch1%24lib=&keyword=&user_name=wjhmiss&user_password=951753",//Post要发送的数据
                Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
                ContentType = "application/x-www-form-urlencoded",
                Host = "www.faxin.cn",
                Referer = "http://www.faxin.cn/login.aspx",
                UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36",
                Header = header,
                Cookie = cookie1,
            };

            result = http.GetHtml(item);
            string cookie2 = HttpHelper.GetSmallCookie(result.Cookie);
            string cookie3 = HttpHelper.GetMergeCookie(cookie1, cookie2);
            //string type = "";
            //string subtype = "";
            //string postdatas = "";

            //type = "国家法律";  //http://www.faxin.cn/lib/zyfl/GetZyflData.ashx
            //subtype = "法律立法解释"; //全部all  法律立法解释010101   司法解释010102   行政法规010103   部门规章010104   其他文件010105
            //postdatas = "keyTitle=&keyContent=&fdep_id=&fwzh=&pdep_id=&sort_id=&xiaoli_id=undefined&Fdate_b=&Fdate_e=&Pdate_b=&Pdate_e=&shixiao_id=&Sdate_b=&Sdate_e=&searchtype=0&showsummary=undefined&ckbInSearch=undefined" +
            //            "&lib=zyfl&chooseNum=010103&firstPage=3&secondPage=3&thirdPage=3&fourthPage=3&fifthPage=3&sixthPage=3&sort_field=&listnum=100&sort_id_left=&xiaoli_id_left=&shixiao_id_left=&fdep_id_left=&isAdvSearch=1&usersearchtype=1";


            ////地方法规  http://www.faxin.cn/lib/dffl/GetDfflData.ashx
            ////全部all   地方性法规010201   地方政府规章010202  地方司法文件010203  地方规范性文件010204   北京010205
            //type = "地方法规";  //
            //subtype = "地方性法规"; //             
            //postdatas = "keyTitle=&keyContent=&fdep_id=&fwzh=&pdep_id=&sort_id=&xiaoli_id=undefined&Fdate_b=&Fdate_e=&Pdate_b=&Pdate_e=&shixiao_id=&Sdate_b=&Sdate_e=&searchtype=0&showsummary=undefined&ckbInSearch=undefined" +
            //            "&lib=dffl&chooseNum=010201&firstPage=3&secondPage=3&thirdPage=3&fourthPage=3&fifthPage=3&sixthPage=3&sort_field=&listnum=100&sort_id_left=&shixiao_id_left=&fdep_id_left=&isAdvSearch=1&usersearchtype=1";


            ////立法资料 http://www.faxin.cn/lib/lfsf/GetLfData.ashx
            ////全部all   全国人大立法资料010301   中央行政立法资料010302   地方人大立法资料010303   地方行政立法资料010304   其他010305
            //type = "立法资料";  //
            //subtype = "全国人大立法资料"; //             
            //postdatas = "keyTitle=&keyContent=&fwzh=&fdep_id=&Fdate_b=&Fdate_e=&pdep_id=undefined&sort_id=&searchtype=0&showsummary=undefined&ckbInSearch=undefined" +
            //            "&lib=lf&chooseNum=010301&firstPage=4&secondPage=4&thirdPage=4&fourthPage=4&fifthPage=4&sort_field=&listnum=10&isAdvSearch=1&usersearchtype=1";



            ////司法资料   http://www.faxin.cn/lib/lfsf/GetLfSfData.ashx
            ////全部all   两高司法资料010401   地方司法资料010402  
            //type = "司法资料";  //
            //subtype = "两高司法资料"; //             
            //postdatas = "keyTitle =&keyContent=&fwzh=&fdep_id=&Fdate_b=&Fdate_e=&pdep_id=undefined&sort_id=&searchtype=0&showsummary=undefined&ckbInSearch=undefined" + 
            //            "&lib=lf&chooseNum=010401&firstPage=4&secondPage=4&thirdPage=4&fourthPage=4&sort_field=&listnum=10&isAdvSearch=1&usersearchtype=1";



            string url = "http://www.faxin.cn/lib/zyfl/GetZyflData.ashx";
            string postdatas = "keyTitle=&keyContent=&fdep_id=&fwzh=&pdep_id=&sort_id=&xiaoli_id=undefined&Fdate_b=&Fdate_e=&Pdate_b=&Pdate_e=&shixiao_id=&Sdate_b=&Sdate_e=&searchtype=0&showsummary=undefined&ckbInSearch=undefined" +
                        "&lib=zyfl&chooseNum=010103&firstPage=3&secondPage=3&thirdPage=3&fourthPage=3&fifthPage=3&sixthPage=3&sort_field=&listnum=100&sort_id_left=&xiaoli_id_left=&shixiao_id_left=&fdep_id_left=&isAdvSearch=1&usersearchtype=1";
            //list
            item = new HttpItem()
            {
                URL = url,//URL     必需项    
                Method = "POST",//URL     可选项 默认为Get   
                PostDataType = PostDataType.String,//默认为字符串，同时支持Byte和文件方法
                PostEncoding = System.Text.Encoding.UTF8,//默认为Default，
                Postdata = postdatas,//Post要发送的数据
                Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
                ContentType = "application/x-www-form-urlencoded",
                Host = "www.faxin.cn",
                Referer = "http://www.faxin.cn/login.aspx",
                UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36",
                Header = header,
                Cookie = cookie3,
            };

            result = http.GetHtml(item);


            url = "http://www.faxin.cn/lib/lfsf/LfContent.aspx?gid=G22956&libid=";
            //detail
            item = new HttpItem()
            {
                URL = url,//URL     必需项    
                Method = "GET",//URL     可选项 默认为Get   
                Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
                ContentType = "application/x-www-form-urlencoded",
                Host = "www.faxin.cn",
                UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36",
                Header = header,
                Cookie = cookie3,
            };

            result = http.GetHtml(item);

            
            //导航目录直接detail 中 html

        }
    }
}